const express = require('express');
const fs = require('fs');
const path = require('path');
const app = express();
const cors = require('cors')
app.use(cors());
app.use(express.static(path.join(__dirname,'images'),{
    maxage: '2h'
}))
const list = require('./data.json')
app.get('/api/list', (req, res) => {
    let start = Math.floor(Math.random() * (list.length - 20));
    res.json(list.slice(start, start + 20));
});

app.listen(4000,()=>{
  console.log(`访问路径：http://localhost:4000/`)
});//http://localhost:4000/
//启服务：vscode右键 Run Code，或者cmd里 node server.js
//终止服务：vscode输出栏右键 Stop Code Run
//如果忘记终止切换项目了，需要在cmd里：
//netstat -ano | findstr :3000    记录最右边的PID
//taskkill /PID 4496 /F           终止进程